package features;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.vecmath.Point3d;

import bReps.CreateBezierLinearPath;
import operationSolids.CompoundSolid;
import operationSolids.OperationBezier;
import CAD.MainFrame;

public class Bezier extends Feature{

	Point3d [] arrayP;
	

	public Bezier(int type, Feature Mother, String name, float posx,
			float posy, float posz, Point3d [] arrayP,
			int face) {
		super(type, Mother, name);
		this.arrayP = arrayP;
		CreateBezierLinearPath bLp = new CreateBezierLinearPath("", arrayP);
		feature=new OperationBezier(bLp.vertexArray, bLp.indexArray, bLp.color3f);
		create(posx, posy, posz, face);
		MainFrame.features.add(this);
		MainFrame.refreshJTree();
	}

	@Override
	void compound() {
		MainFrame.block  = new Block ("comp", CompoundSolid.DIFFERENCE, MainFrame.block, feature);
		
	}

	@Override
	void translate() {
		feature.translate(placement.getX(), placement.getZ() ,-placement.getY() );
		switch (MainFrame.Face) {
		case MainFrame.BACKFACE:
			feature.translate(-MainFrame.block.width/2, MainFrame.block.length/2,MainFrame.block.height/2);
			break;
		case MainFrame.FRONTFACE:
			feature.translate(-MainFrame.block.width/2, MainFrame.block.length/2,MainFrame.block.height/2);
			break;
		case MainFrame.EASTFACE:
			feature.translate(-MainFrame.block.length/2,MainFrame.block.width/2,MainFrame.block.height/2 );
			break;
		case MainFrame.WESTFACE:
			feature.translate(-MainFrame.block.length/2,MainFrame.block.width/2,MainFrame.block.height/2 );
			break;
		case MainFrame.LOWERFACE:
			feature.translate(-MainFrame.block.width/2, MainFrame.block.height/2,MainFrame.block.length/2);
			break;
		case MainFrame.TOPFACE:
			feature.translate(-MainFrame.block.width/2, MainFrame.block.height/2,MainFrame.block.length/2);
			break;

		default:
			System.out.println("erro");
			break;
		}
		
	}

	@Override
	public void drawNode(DefaultMutableTreeNode node) {
		node.add(
				new DefaultMutableTreeNode(
				"Point 1:"+arrayP[0]+"mm")
				);
		node.add(
				new DefaultMutableTreeNode(
				"Point 2:"+arrayP[1]+"mm")
				);
		node.add(
				new DefaultMutableTreeNode(
				"Point 3:"+arrayP[2]+"mm")
				);
		node.add(
				new DefaultMutableTreeNode(
				"Point 4:"+arrayP[3]+"mm")
				);
		
	}

}
